<template>
    <ListPage ref="page" :query="query" :api="getZzhGlList">

        <template #search="{ page, hiddenColumns }">
            <PageSearch ref="search" :query="query" :page="page" has-box @search="() => ($refs.page as any).getData()">
                <template #auth>
                </template>
                <template #input="{ }">
                    <SearchInput v-model="query.keyword" placeholder="客户名称/店铺名称/业务名称" :data="query"
                        :hidden-columns="(hiddenColumns as any)" @trigger="(e) => ($refs.search as any).trigger(e)"
                        @search="() => ($refs.page as any).getData()"
                        @change-column="(prop) => ($refs.page as any).changeColumn(prop)"></SearchInput>
                </template>
                <ElFormItem label="是否分配">
                    <ElSelect filterable clearable :="$attrs" placeholder="" v-model="query.isFP">
                        <ElOption key="全部" label="全部" value="全部" />
                        <ElOption key="已分配" label="已分配" value="已分配" />
                        <ElOption key="未分配" label="未分配" value="未分配" />
                    </ElSelect>
                </ElFormItem>
            </PageSearch>
        </template>


        <template #table="{ data, hiddenColumns }">
            <ListTable :data="data" :hidden-columns="(hiddenColumns as any)" @openAddZzh="openAddZzh"
                @openEditZzh="openEditZzh" @zzhStop="zzhStop" @refreshData="refreshData">
            </ListTable>
        </template>

        <template #pagination="{ page, total }">
            <PagePagination :page="page" :total="total" @changePage="(v) => ($refs.page as any).changePage(v)">
            </PagePagination>
        </template>
    </ListPage>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import ListPage from '@/components/list-page/ListPage.vue'
import ListTable from './ListTable.vue'
import PageSearch from '@/components/list-page/PageSearch.vue'
import SearchInput from '@/components/list-page/SearchInput.vue'
import { getZzhGlList, postZzhStop } from '../api'
import { addZzhDialog } from '@/views/menus/n-customer-manage-shop-new/dialog/addZzh.ts'
import PagePagination from '@/components/list-page/PagePagination.vue'

const page = ref()

const query = reactive({
    keyword: '',
    isFP: '全部'
})

const openAddZzh = async (row) => {
    const customerShopBusinessId = row.customerShopBusinessId;
    await addZzhDialog.title('新增子账号').open({ row: { customerShopBusinessId } });
    page.value && page.value.getData();
}

const openEditZzh = async (row) => {
    await addZzhDialog.title('编辑子账号').open({ row });
    page.value && page.value.getData();
}

const zzhStop = async (row) => {
    let res = await postZzhStop(row);
    console.log(res);
}

const refreshData = async () => {
    page.value && page.value.getData();
}

</script>